// nvue动画模块实现细节抽离在外部文件
import animationMap, { type AniMap } from "./nvue.ani-map.js";

// 定义一个一定时间后自动成功的promise，让调用nextTick方法处，进入下一个then方法
export const nextTick = () =>
  new Promise((resolve) => setTimeout(resolve, 1000 / 50));

// #ifndef APP-NVUE
// 定义类名，通过给元素动态切换类名，赋予元素一定的css动画样式
export const getClassNames = (name: string) => ({
  enter: `e-${name}-enter e-${name}-enter-active`,
  "enter-to": `e-${name}-enter-to e-${name}-enter-active`,
  leave: `e-${name}-leave e-${name}-leave-active`,
  "leave-to": `e-${name}-leave-to e-${name}-leave-active`,
});
// #endif

// #ifdef APP-NVUE
// 引入animation动画模块，文档见：
// https://uniapp.dcloud.net.cn/tutorial/nvue-api.html#animation
export const animation = uni.requireNativePlugin("animation") as any;
export const getStyle = (name: keyof AniMap) => animationMap[name];
// #endif
